/* 
 * Original work Copyright (c) 2013-2015, Roland Bock
 * Modified work Copyright (c) 2016, Aaron Bishop
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 * 
 * Redistributions in binary form must reproduce the above copyright notice, this
 * list of conditions and the following disclaimer in the documentation and/or
 * other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef TEST_SAMPLE_H
#define TEST_SAMPLE_H

#include <sqlpp11/table.h>
#include <sqlpp11/data_types.h>
#include <sqlpp11/char_sequence.h>

#define DELARE_FIELD(field,type)\
struct field { \
	struct _alias_t { \
		static constexpr const char _literal[] = #field; \
		using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;\
		template<typename T>\
			struct _member_t {\
				T field;\
				T& operator()() { return field; }\
				const T& operator()() const { return field; }\
			};\
	};\
	using _traits = sqlpp::make_traits<type>;\
	static constexpr const char* ColName = _alias_t::_literal;\
};\
namespace Field { \
	static constexpr const char* field = field::_alias_t::_literal;\
}\

namespace Tab_xb_waterdata
{
	DELARE_FIELD(id, sqlpp::integral)
	DELARE_FIELD(deviceid, sqlpp::integral)
	DELARE_FIELD(water, sqlpp::floating_point)
	DELARE_FIELD(createdate, sqlpp::time_point)
	struct xb_waterdata : sqlpp::table_t<xb_waterdata
		, id
		, deviceid
		, water
		, createdate> {
		struct _alias_t {
			static constexpr const char _literal[] = "xb_waterdata"; 
			using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
			template<typename T> struct _member_t {
				T xb_waterdata; T& operator()() {
					return xb_waterdata;
				} const T& operator()() const {
					return xb_waterdata;
				}
			};
		};
	};
}

namespace Tab_xb_device
{
	DELARE_FIELD(id, sqlpp::integral)
	DELARE_FIELD(deviceid, sqlpp::integral)
	DELARE_FIELD(devicename, sqlpp::text)
	struct xb_device : sqlpp::table_t<xb_device
		, id
		, deviceid
		, devicename> {
		struct _alias_t {
			static constexpr const char _literal[] = "xb_device";
			using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
			template<typename T> struct _member_t {
				T xb_waterdata; T& operator()() {
					return xb_waterdata;
				} const T& operator()() const {
					return xb_waterdata;
				}
			};
		};
	};
}

namespace Tab_Weather
{
	DELARE_FIELD(id, sqlpp::integer)
	DELARE_FIELD(g, sqlpp::bigint)
	DELARE_FIELD(timestamp, sqlpp::bigint)

	struct anal1km : sqlpp::table_t<anal1km
		, timestamp> {
		struct _alias_t {
			static constexpr const char _literal[] = "anal1km";
			using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
			template<typename T> struct _member_t {
				T xb_waterdata; T& operator()() {
					return xb_waterdata;
				} const T& operator()() const {
					return xb_waterdata;
				}
			};
		};
	};

	struct anal3km : sqlpp::table_t<anal3km
		, timestamp> {
		struct _alias_t {
			static constexpr const char _literal[] = "anal3km";
			using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
			template<typename T> struct _member_t {
				T xb_waterdata; T& operator()() {
					return xb_waterdata;
				} const T& operator()() const {
					return xb_waterdata;
				}
			};
		};
	};

	struct fcst3km : sqlpp::table_t<fcst3km
		, id
		, g
		, timestamp> {
		struct _alias_t {
			static constexpr const char _literal[] = "fcst3km";
			using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
			template<typename T> struct _member_t {
				T xb_waterdata; T& operator()() {
					return xb_waterdata;
				} const T& operator()() const {
					return xb_waterdata;
				}
			};
		};
	};
}

namespace Tab_FDB
{
	DELARE_FIELD(i, sqlpp::integer)
	DELARE_FIELD(k, sqlpp::text)
	DELARE_FIELD(b, sqlpp::integer)
	DELARE_FIELD(e, sqlpp::integer)

	struct IDX : sqlpp::table_t<IDX
		, i, k, b, e> {
		struct _alias_t {
			static constexpr const char _literal[] = "IDX";
			using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
			template<typename T> struct _member_t {
				T _tab; 
				T& operator()() {
					return _tab;
				} const T& operator()() const {
					return _tab;
				}
			};
		};
	};

		DELARE_FIELD(file_gid, sqlpp::integer)
		DELARE_FIELD(file_path, sqlpp::text)
		DELARE_FIELD(file_size, sqlpp::integer)
		DELARE_FIELD(file_md5, sqlpp::text)
		DELARE_FIELD(file_data, sqlpp::blob)

		struct table_file_info : sqlpp::table_t<table_file_info
		, file_gid, file_path, file_md5> {
		struct _alias_t {
			static constexpr const char _literal[] = "file_info";
			using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
			template<typename T> struct _member_t {
				T _tab;
				T& operator()() {
					return _tab;
				} const T& operator()() const {
					return _tab;
				}
			};
		};
	};

	struct table_file_data : sqlpp::table_t<table_file_data
		, file_md5, file_size, file_data> {
		struct _alias_t {
			static constexpr const char _literal[] = "file_data";
			using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
			template<typename T> struct _member_t {
				T _tab;
				T& operator()() {
					return _tab;
				} const T& operator()() const {
					return _tab;
				}
			};
		};
	};
}

#endif
